require.config({
    baseUrl: '/SH/public/static/js/',
	paths: {
		vue: "encaptool/encvue",
        iview: "utiltool/iview/iview",
        wangEditor: "utiltool/editortool/wangEditor",
        axios:"encaptool/encaxios"
	},
	shim: {
		vue: {  
			exports:'Vue'  
		},  
		iview: [  
			'vue'  
        ]
	  }
});
require(['vue','iview','wangEditor','axios'],function(Vue,iview,wangEditor,axios){
    Vue.use(iview);

	new Vue({
		el: '#js_editor',
		data(){
			return {
                editor: {},
                title: ''
			}
		},
		mounted() {
            this.init();
		},
		computed: {
        },
        methods: {
            init(){
                this.editor = new wangEditor('#editor');
                this.editor.customConfig.showLinkImg = false;
                this.editor.customConfig.uploadImgShowBase64 = true; 
                this.editor.create();
            },
            comeBack(){
                window.history.back(-1);
            },
            toSubmit(){
                //后台获取时间
                //后台处理xss
                var content = this.editor.txt.getJSON();
                var article = {
                    author: '',
                    type: '',
                    title: this.title,
                    content: content,
                    picture: ''
                }
                var msg = {
                    data: article,
                    setting: {
                        url: this.baseurl + 'forum/submitArticle',
                        method: 'post'
                    }
                }
                console.log(msg);
                axios.call(this, this.toCallBack, msg);
            },
            toCallBack(msg){
                if(msg.status === 0){
                    this.$Notice.success({
                        title: '发布成功',
                        desc: '发表文章成功!!',
                        duration: 3,
                        onClose: function(){
                            console.log("woyaotiaozhuanle");
                        }
                    });
                }else{
                    this.$Notice.error({
                        title: '发布失败',
                        desc: '发表文章失败!!',
                        duration: 3,
                        onClose: function(){
                            console.log("woyaotiaozhuanle");
                        }
                    });
                }

            }
        }
	})
});
